from django.views import View
# 导入返回响应
from SaaSDevelTool.data_return_response import create_response
# 导入错误信息装饰器
from SaaSDevelTool.data_return_response import error_message_detection
# 导入数据库连接
from SaaSDevelTool.data_mysql_data import db

"""企业已开启功能包查看"""


class SaaSDataTenementPackageDelete(View):
    @error_message_detection
    def post(self, request):
        # 获取企业编号
        tenement_id = request.POST.get("tenement_id")
        # 获取功能包编号
        package_id = request.POST.get("package_id")

        # 判断对应的企业编号
        if not tenement_id:
            return create_response(code=400, msg="企业编号传递错误。")

        # 判断大模块编号
        if not package_id:
            return create_response(code=400, msg="大模块编号传递错误。")

        # 关闭，拼接删除语句
        delete_map_tenement_package_table_sql = """
            DELETE FROM 
                db_saas_center.map_tenement_package_table
            WHERE 
                tenement_id = {}     
            AND 
                package_id = {}
            ;""".format(tenement_id, package_id)
        # 执行修改语句
        db.update(delete_map_tenement_package_table_sql)
        # 返回响应
        return create_response(code=200, msg="功能包禁用成功。")

